class Solution
{
public:
    int distinctSubseqII(string s)
    {
        vector<int> lastOccur(26, -1);
        int n = s.size();
        vector<int> dp(n, 1);
        for (int i = 0; i < n; ++i)
        {
            for (int occur : lastOccur)
            {
                if (occur != -1)
                {
                    dp[i] += dp[occur];
                    dp[i] %= 1000000007;
                }
            }
            lastOccur[s[i] - 'a'] = i;
        }
        int answer = 0;
        for (int occur : lastOccur)
        {
            if (occur != -1)
            {
                answer += dp[occur];
                answer %= 1000000007;
            }
        }
        return answer;
    }
};